FROM php:7.2-cli-alpine

RUN sed -i 's/http:\/\/dl-cdn.alpinelinux.org/https:\/\/mirrors.cloud.tencent.com/g' /etc/apk/repositories

RUN apk add -u --no-cache tzdata \
 && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

COPY ssh/* /root/.ssh/ 
RUN chmod 400 /root/.ssh/id_rsa

RUN apk update && apk upgrade && \
    apk add --no-cache curl \
        curl-dev \
        autoconf \
        openssh \
        gcc \
        make \
        g++ \
        zlib-dev \
        wget \
        git \
        vim \
        graphviz \
        libpng-dev \
        libpq \
        icu-dev \
        libffi-dev \
        freetype-dev \
        libxslt-dev \
        libjpeg-turbo-dev \
        libwebp-dev \
        libzip-dev \
        libmemcached-dev \
        libmcrypt-dev \
        npm \
        bash \
        librdkafka-dev && \
    docker-php-ext-configure gd \
      --with-gd \
      --with-freetype-dir=/usr/include/ \
      --with-png-dir=/usr/include/ \
      --with-jpeg-dir=/usr/include/ \
      --with-webp-dir=/usr/include/ && \
    docker-php-ext-install pdo_mysql mysqli gd exif intl xsl soap zip opcache sockets bcmath pcntl && \
    docker-php-source delete

RUN pecl install redis-5.0.2 memcached-3.1.4 rdkafka yaf-3.0.8 yar-2.0.5 mcrypt \
    && docker-php-ext-enable redis memcached rdkafka yaf yar mcrypt \
    && apk del autoconf gcc make g++ \
    && rm -fr /var/cache/apk/* /tmp/* /usr/share/man

COPY composer /usr/local/bin/

RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    && composer global require hirak/prestissimo \
    && composer global require "squizlabs/php_codesniffer=*" \
    && composer global require phpunit/phpunit \
    && composer global require phpmd/phpmd \
    && composer global require phploc/phploc \
    && composer global require sebastian/phpcpd \
    && composer global require nunomaduro/phpinsights --dev \
    && composer clearcache \
    && npm install -g pm2

COPY php-config/php.ini "$PHP_INI_DIR"

ENV PATH=$PATH:/root/.composer/vendor/bin
ENV TZ Asia/Shanghai
